package com.hatricks.is.base.monitor;

import cn.hutool.system.oshi.OshiUtil;
import lombok.SneakyThrows;
import oshi.software.os.OSProcess;

import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;

/**
 * @packageName: com.hatricks.base.monitor
 * @className: OshiSummary
 * @author: yanyh yanyh@glodon.com
 * @date: 2023/12/5 20:21
 * @description:
 */
public class OshiSummary {
    @SneakyThrows
    public static void main(String[] args) {
        OSProcess currentProcess = OshiUtil.getCurrentProcess();
        System.out.println(currentProcess.getOpenFiles());

        MBeanServer mbs = ManagementFactory. getPlatformMBeanServer() ;
        ObjectName objectName = new ObjectName("java.nio:type=BufferPool,name=direct" ) ;
        MBeanInfo info = mbs.getMBeanInfo(objectName) ;
        for(MBeanAttributeInfo i : info.getAttributes()) {
            System.out .println(i.getName() + ":" + mbs.getAttribute(objectName , i.getName()));
        }

    }
}
